<template>
  <div class="head-container">
    <!-- 搜索 -->
    <div v-show="sup_this.searchToggle">
      <el-select
        v-model="paramBean.materialReqStatus"
        size="mini"
        style="width: 180px"
        clearable
        placeholder="请选择发料状态"
      >
        <el-option
          v-for="item in dicts.material_req_status"
          :key="item.id"
          :label="item.dictName"
          :value="item.dictCode"
        />
      </el-select>
      <el-input
        v-model="paramBean.sysGenCode"
        clearable
        placeholder="输入系统编号搜索"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="sup_this.toQuery"
      />
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-search"
        @click="sup_this.toQuery"
        >搜索</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-refresh-left"
        @click="sup_this.resetQuery()"
        >重置</el-button
      >
    </div>
    <div class="crud-opts">
      <!-- <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','OEM_MATERIAL_SEND_ALL','OEM_MATERIAL_SEND_SUBMIT']"
        v-loading="submitLoading"
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-check"
        @click="doMultiSend">发料</el-button> -->
      <DataGridOpts
        :sup_this="sup_this"
        @refreshClick="refreshClick"
        @searchClick="searchClick"
      />
    </div>
  </div>
</template>

<script>
import oemMaterialReq from "@/api/prod/OemMaterialReq";

export default {
  components: {},
  dictTypes: ["material_req_status"],
  props: {
    paramBean: {
      type: Object,
      required: true,
    },
    sup_this: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      submitLoading: false,
    };
  },
  methods: {
    refreshClick() {
      this.sup_this.init();
    },
    searchClick() {
      this.sup_this.toggleSearch();
    },
    doMultiSend() {
      const _this = this.sup_this;
      const selectIds = [];
      _this.selectedGridRows.forEach((row) => {
        selectIds.push(row.id);
      });
      if (selectIds.length === 0) {
        this.$message({
          message: "请选择记录",
          type: "warning",
        });
        return;
      }
      this.submitLoading = true;
      this.$confirm("确认要发料?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          const data = { idList: selectIds, listSubmit: true };
          oemMaterialReq
            .postRequestByName("doMaterialSendSubmit", data)
            .then((res) => {
              this.submitLoading = false;
              _this.init();
            })
            .catch((err) => {
              this.submitLoading = false;
              console.log(err);
            });
        })
        .catch(() => {
          this.submitLoading = false;
        });
    },
  },
};
</script>
